package gomz.pres.admin;

import gomz.pres.GUIMain;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;

/**
 * Diese Klasse erstellt das GUI der Benutzerverwaltung in der Verwaltung
 * 
 * @author Dilji
 */

public class GUIAUseradministration {

	// all the variables for main panels
	private JPanel plUseradministration;
	private JPanel plUseradministrationNord;
	private JScrollPane spUseradministration;

	// all the variables
	private JLabel lbVUseradministrationTitle;
	private JScrollPane spVlist;
	private JList liVlist;
	private JLabel lbVuser;
	private JTextField tfVuser;
	private JLabel lbVpw;
	private JPasswordField pfVpw;
	private JLabel lbVfirstname;
	private JTextField tfVfirstname;
	private JLabel lbVlastname;
	private JTextField tfVlastname;
	private JLabel lbVemail;
	private JTextField tfVemail;
	private JLabel lbVlang;
	private JComboBox cxVlang;
	private JLabel lbVadmin;
	private JCheckBox cbVadmin;
	private JButton btVdel;
	private JButton btVsave;
	private JButton btVcan;

	/**
	 * Erstellt das GUI fuer die Benutzerverwaltung
	 * @param userList fuellt die Benutzerliste
	 * @return gibt das GUI zurueck
	 */
	public JScrollPane getTab(String[] userList) {

		// initialize the panels, add to scrollpane and set position
		this.plUseradministration = new JPanel();
		this.plUseradministrationNord = new JPanel();
		this.spUseradministration = new JScrollPane(plUseradministrationNord);
		this.plUseradministrationNord.setLayout(new BorderLayout());
		this.plUseradministrationNord.setBorder(new EmptyBorder((2 * GUIMain.getAbstand()), 0, GUIMain.getAbstand(), 0));
		this.plUseradministrationNord.add(plUseradministration, BorderLayout.NORTH);

		// set background of main panels
		this.plUseradministration.setBackground(Color.WHITE);
		this.plUseradministrationNord.setBackground(Color.WHITE);

		// initialize the components of overview
		this.lbVUseradministrationTitle = new JLabel("Benutzerverwaltung");
		this.liVlist = new JList(userList);
		this.liVlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		this.spVlist = new JScrollPane(liVlist);
		this.lbVuser = new JLabel("Benutzername:");
		this.tfVuser = new JTextField();
		this.lbVpw = new JLabel("Passwort:");
		this.pfVpw = new JPasswordField();
		this.lbVfirstname = new JLabel("Vorname:");
		this.tfVfirstname = new JTextField();
		this.lbVlastname = new JLabel("Nachname:");
		this.tfVlastname = new JTextField();
		this.lbVemail = new JLabel("E-Mail:");
		this.tfVemail = new JTextField();
		this.lbVlang = new JLabel("Sprache:");
		String langList[] = { "Deutsch", "English" };
		this.cxVlang = new JComboBox(langList);
		this.lbVadmin = new JLabel("Admin:");
		this.cbVadmin = new JCheckBox();
		this.btVdel = new JButton("L\u00f6schen");
		this.btVsave = new JButton("Speichern");
		this.btVcan = new JButton("Abbrechen");

		// FontSize for title
		this.lbVUseradministrationTitle.setFont(GUIMain.getTitlefont());
		this.lbVUseradministrationTitle.setForeground(GUIMain.getTitleblue());

		// Backgroundcolor for Checkbox Admin
		this.cbVadmin.setBackground(Color.WHITE);

		// size of scrollpane from list
		this.spVlist.setPreferredSize(new Dimension(295, 350));
		this.spVlist.setMaximumSize(new Dimension(295, 350));

		// size of textfields
		this.tfVuser.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVuser.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.pfVpw.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.pfVpw.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVfirstname.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVfirstname.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVlastname.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVlastname.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVemail.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfVemail.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.cxVlang.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.cxVlang.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));

		// size of buttons
		this.btVsave.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btVsave.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btVcan.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btVcan.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btVdel.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btVdel.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));

		// set bordercoller and gap
		this.spVlist.setBorder(GUIMain.getBorderColor());
		this.tfVuser.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.pfVpw.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfVfirstname.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfVlastname.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfVemail.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.cxVlang.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));

		// BOX
		Box btVbox = Box.createHorizontalBox();
		btVbox.add(btVsave);
		btVbox.add(Box.createHorizontalStrut(GUIMain.getAbstand()));
		btVbox.add(btVcan);

		// BOX
		Box btVbox2 = Box.createHorizontalBox();
		btVbox2.add(btVdel);

		// scroll speed
		this.spUseradministration.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());
		this.spVlist.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());

		// position of components
		this.plUseradministration.setLayout(new GridBagLayout());
		GridBagConstraints cv = new GridBagConstraints();
		cv.fill = GridBagConstraints.HORIZONTAL; // in x-Achse ausfuellen
		cv.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cv.anchor = GridBagConstraints.NORTHWEST; // Ausrichtung oben

		cv.gridx = 0; // Spalte 1
		cv.gridy = 0; // Zeile 1
		cv.gridwidth = 2;
		plUseradministration.add(lbVUseradministrationTitle, cv); // label Title
		cv.gridx = 1; // Spalte 2
		cv.gridy = 0; // Zeile 1
		cv.gridwidth = 1;
		// plUseradministration.add(, cv); // Com
		cv.gridx = 2; // Spalte 3
		cv.gridy = 0; // Zeile 1
		// plUseradministration.add(, cv); // Com

		cv.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, (3 * GUIMain.getAbstand()));
		cv.gridx = 0; // Spalte 1
		cv.gridy = 1; // Zeile 2
		cv.gridheight = 8;
		plUseradministration.add(spVlist, cv); // Liste Benutzer
		cv.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cv.gridx = 1; // Spalte 2
		cv.gridy = 1; // Zeile 2
		cv.gridheight = 1;
		plUseradministration.add(lbVuser, cv); // Label User
		cv.gridx = 2; // Spalte 3
		cv.gridy = 1; // Zeile 2
		plUseradministration.add(tfVuser, cv); // TextField User

		cv.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cv.gridx = 0; // Spalte 1
		cv.gridy = 2; // Zeile 3
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 2; // Zeile 3
		plUseradministration.add(lbVpw, cv); // Label Passwort
		cv.gridx = 2; // Spalte 3
		cv.gridy = 2; // Zeile 3
		plUseradministration.add(pfVpw, cv); // PasswordField Passwort

		cv.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cv.gridx = 0; // Spalte 1
		cv.gridy = 3; // Zeile 4
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 3; // Zeile 4
		plUseradministration.add(lbVfirstname, cv); // Label Vorname
		cv.gridx = 2; // Spalte 3
		cv.gridy = 3; // Zeile 4
		plUseradministration.add(tfVfirstname, cv); // TextField Vorname

		cv.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cv.gridx = 0; // Spalte 1
		cv.gridy = 4; // Zeile 5
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 4; // Zeile 5
		plUseradministration.add(lbVlastname, cv); // Label Nachname
		cv.gridx = 2; // Spalte 3
		cv.gridy = 4; // Zeile 5
		plUseradministration.add(tfVlastname, cv); // TextField Nachname

		cv.gridx = 0; // Spalte 1
		cv.gridy = 5; // Zeile 6
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 5; // Zeile 6
		plUseradministration.add(lbVemail, cv); // Label E-Mail
		cv.gridx = 2; // Spalte 3
		cv.gridy = 5; // Zeile 6
		plUseradministration.add(tfVemail, cv); // TextField E-Mail

		cv.gridx = 0; // Spalte 1
		cv.gridy = 6; // Zeile 7
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 6; // Zeile 7
		plUseradministration.add(lbVlang, cv); // Label Sprache
		cv.gridx = 2; // Spalte 3
		cv.gridy = 6; // Zeile 7
		plUseradministration.add(cxVlang, cv); // ComboBox Sprache

		cv.gridx = 0; // Spalte 1
		cv.gridy = 7; // Zeile 8
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 7; // Zeile 8
		plUseradministration.add(lbVadmin, cv); // Label Admin
		cv.gridx = 2; // Spalte 3
		cv.gridy = 7; // Zeile 8
		plUseradministration.add(cbVadmin, cv); // ComboBox Admin

		cv.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), GUIMain.getAbstand(), GUIMain.getAbstand());
		cv.gridx = 0; // Spalte 1
		cv.gridy = 8; // Zeile 9
		// plUseradministration.add(, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 8; // Zeile 9
		// plUseradministration.add(, cv); // Com
		cv.gridx = 2; // Spalte 3
		cv.gridy = 8; // Zeile 9
		plUseradministration.add(btVbox, cv); // Box

		cv.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), GUIMain.getAbstand(), GUIMain.getAbstand());
		cv.gridx = 0; // Spalte 1
		cv.gridy = 9; // Zeile 10
		plUseradministration.add(btVbox2, cv); // Com
		cv.gridx = 1; // Spalte 2
		cv.gridy = 9; // Zeile 10
		// plUseradministration.add(, cv); // Com
		cv.gridx = 2; // Spalte 3
		cv.gridy = 9; // Zeile 10
		// plUseradministration.add(, cv); // Com

		return (spUseradministration);
	}
	
	// ********************************************************************************
	// Getters und Setters
	// ********************************************************************************
	
	public JScrollPane getSpVlist() {
		return spVlist;
	}

	public void setSpVlist(JScrollPane spVlist) {
		this.spVlist = spVlist;
	}

	public JList getLiVlist() {
		return liVlist;
	}

	public void setLiVlist(JList liVlist) {
		this.liVlist = liVlist;
	}

	public JTextField getTfVuser() {
		return tfVuser;
	}

	public void setTfVuser(JTextField tfVuser) {
		this.tfVuser = tfVuser;
	}

	public JPasswordField getPfVpw() {
		return pfVpw;
	}

	public void setPfVpw(JPasswordField pfVpw) {
		this.pfVpw = pfVpw;
	}

	public JTextField getTfVfirstname() {
		return tfVfirstname;
	}

	public void setTfVfirstname(JTextField tfVfirstname) {
		this.tfVfirstname = tfVfirstname;
	}

	public JTextField getTfVlastname() {
		return tfVlastname;
	}

	public void setTfVlastname(JTextField tfVlastname) {
		this.tfVlastname = tfVlastname;
	}

	public JTextField getTfVemail() {
		return tfVemail;
	}

	public void setTfVemail(JTextField tfVemail) {
		this.tfVemail = tfVemail;
	}

	public JComboBox getCxVlang() {
		return cxVlang;
	}

	public void setCxVlang(JComboBox cxVlang) {
		this.cxVlang = cxVlang;
	}

	public JCheckBox getCbVadmin() {
		return cbVadmin;
	}

	public void setCbVadmin(JCheckBox cbVadmin) {
		this.cbVadmin = cbVadmin;
	}

	public JButton getBtVdel() {
		return btVdel;
	}

	public void setBtVdel(JButton btVdel) {
		this.btVdel = btVdel;
	}

	public JButton getBtVsave() {
		return btVsave;
	}

	public void setBtVsave(JButton btVsave) {
		this.btVsave = btVsave;
	}

	public JButton getBtVcan() {
		return btVcan;
	}

	public void setBtVcan(JButton btVcan) {
		this.btVcan = btVcan;
	}
}
